﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Text;

namespace A_Modules.ImageWaterMark
{
    public class ImageWaterMark
    {
        //private Graphics myGraphics;
        public ImageWaterMark()
        {
        }

        public void Test()
        {
            string basestr = AppDomain.CurrentDomain.BaseDirectory;

            string tmpsrc = @"D:\DevProjects\Myprojects\DotNet\iceternally-dotnet-test\trunk\BaseLab\BaseLab20\A-Modules\ImageTransparent\Src\Src2.tif";

            string tmpWaterMark = @"D:\DevProjects\Myprojects\DotNet\iceternally-dotnet-test\trunk\BaseLab\BaseLab20\A-Modules\ImageWaterMark\SRC\Square_1.bmp";
            
            var srcIamge = Image.FromFile(tmpsrc);
            var myGraphics = this.CreateGrapgic(srcIamge);

            var vImage = Image.FromFile(tmpWaterMark);
            
            var rec = new Rectangle(450, 304, vImage.Width, vImage.Height);
            myGraphics = this.GraphicsDraw(myGraphics, vImage, rec);
            srcIamge.Save(@"D:\DevProjects\Myprojects\DotNet\iceternally-dotnet-test\trunk\BaseLab\BaseLab20\A-Modules\ImageWaterMark\SRC\Res1.tif", ImageFormat.Tiff);
            
            myGraphics.Dispose();
            vImage.Dispose();

            //Graphics graphics = Graphics.FromImage(Image.FromFile(tmpsrc));
            //graphics.SmoothingMode = SmoothingMode.HighQuality;
        }

        private Graphics CreateGrapgic(Image baseImage)
        {
            var myGraphics = Graphics.FromImage(baseImage);

            return myGraphics;
        }

        private Graphics GraphicsDraw(Graphics bGraphics,Image wImage,Rectangle rectangle)
        {
            bGraphics.DrawImage(
                                wImage,
                                rectangle,
                        0,
                        0,
                        wImage.Width,
                        wImage.Height,
                        GraphicsUnit.Pixel);
            wImage.Dispose();

            return bGraphics;
        }
    }
}
